-- 火焰区域类
FireArea = {}
FireArea.__index = FireArea

function FireArea:new(x, y, side, damage, duration)
    local fireArea = {
        x = x,
        y = y,
        side = side, -- 那个玩家的
        damage = damage,
        duration = duration,
        lifetime = 5  -- 火焰区域存在时间
    }
    setmetatable(fireArea, FireArea)
    return fireArea
end

function FireArea:update(dt, enemies)
    self.lifetime = self.lifetime - dt
    if self.lifetime <= 0 then
        return false  -- 火焰区域结束
    end

    -- 检查敌人是否在火焰区域内
    for _, enemy in ipairs(enemies) do
        local distance = math.sqrt((enemy.x - self.x)^2 + (enemy.y - self.y)^2)
        if distance < 20 then  -- 设定火焰区域范围
            if enemy.health > 0 then
                enemy.health = enemy.health - self.damage
                if enemy.health <= 0 then
                    enemy.health =0
                    enemy.alive = false
                    if self.side ==1 then
                        -- playeronescore  =playeronescore  +1
                        enemy.deadbyside = self.side
                    else
                        -- playertwoscore   =playertwoscore  +1
                        enemy.deadbyside = self.side
                    end
                end
                print("敌人受到火焰伤害，剩余生命：" .. enemy.health)
            end
        end
    end

    return true  -- 火焰区域仍然有效
end
